package com.pagepub.expo.action;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.pagepub.core.tag.message.HtmlMessageBox;
import com.pagepub.core.tag.message.HtmlMessageProcess;
import com.pagepub.expo.entity.CorpCommpany;

public class BaseAction extends  ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public String execute() throws Exception {
		System.out.println("this is BaseAction execute");
		return null;
	}
	
	public String getoperator(	HttpServletRequest request){
		HttpSession session = request.getSession(true);
		CorpCommpany corpCommpany = (CorpCommpany) session.getAttribute("corpCommpany");
		return corpCommpany.getId()+"";
		
	}
	
	public String displayMessage(HttpServletRequest request,HtmlMessageBox hmb,String message) {
		String display="bigmessage";
		HtmlMessageProcess hmp = new HtmlMessageProcess(hmb, request);
		hmb = hmp.process();
		if("small".equals(message)){
			display="smallmessage";
		}
		return display;
	}
	
	
	public String getCookieValue(String name)
	{
		HttpServletRequest request = ServletActionContext.getRequest();
		Cookie cookies[] = request.getCookies();
		if (cookies != null)
		{
			for (Cookie cookie : cookies)
			{

				if (!cookie.getName().equals(name))
					continue;
				return cookie.getValue();
			}

		}
		return null;
	}

	public void saveCookie(String name, String value, int maxAge)
	{
		HttpServletResponse response = ServletActionContext.getResponse();
		Cookie cookie = new Cookie(name,
				value);
		cookie.setPath("/");
		cookie.setMaxAge(maxAge);
		response.addCookie(cookie);
	}

}
